package org.blame.myRabbitMQ;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class producerDemo {
    public static void main(String[] args) throws IOException, TimeoutException {
//        1.建立连接
        ConnectionFactory connectionFactory=new ConnectionFactory();
        connectionFactory.setHost("123.57.4.74");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("admin");
        connectionFactory.setPassword("admin");
        connectionFactory.setVirtualHost("blog");

        Connection connection= connectionFactory.newConnection();

//        2.开启信道
        Channel channel=connection.createChannel();
//        申明队列，使用的是内置的交换机
//        如果队列不存在，则创建队列，否则则不创建
        channel.queueDeclare("666",true,false,false,null);
        for (int i = 0; i < 8; i++) {
            String meg="测试一下消息队列的生产者";
            channel.basicPublish("","666",null,meg.getBytes());
        }
        System.out.println("消息发送成功");
        channel.close();
        connection.close();
    }
}
